package javaweb_work01.classesContrl.Dao;

import javaweb_work01.classesContrl.Entity.Classes;
import javaweb_work01.login.Utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * 访问数据库实现查找指定班级信息的功能
 */
public class CheckClassesDaoImp implements CheckClassesDao{
    @Override
    public List<Classes> checkClasses(String className) {
        try {
            //使用连接池创建QueryRunner对象
            QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
            //编写sql语句
            String sql = "select * from class where class_name = ?";
            //执行语句
            List<Classes> query = qr.query(sql, new BeanListHandler<Classes>(Classes.class), className);
            //返回结果集
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        //如没有查找到则返回空值
        return null;
    }
}
